package tech.gismap.admin.service;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import tech.gismap.admin.domain.OaUser;
import tech.gismap.admin.web.bo.OaUserBo;
import tech.gismap.admin.web.vo.OaUserVo;
import tech.gismap.admin.mapper.OaUserMapper;
import tech.gismap.common.mybatis.core.page.PageQuery;
import tech.gismap.common.mybatis.core.page.TableDataInfo;

/**
* 用户信息表
*/
@Slf4j
@Service
@RequiredArgsConstructor
public class OaUserService {

    private final OaUserMapper baseMapper;

    public TableDataInfo<OaUserVo> selectPageList(OaUserBo bo, PageQuery pageQuery) {
        Page<OaUserVo> page = baseMapper.selectVoPage(pageQuery.build(), this.buildQueryWrapper(bo));
        return TableDataInfo.build(page);
    }

    private Wrapper<OaUser> buildQueryWrapper(OaUserBo bo) {
        LambdaQueryWrapper<OaUser> wrapper = Wrappers.lambdaQuery();
        wrapper.orderByDesc(OaUser::getUpdateTime);
        return wrapper;
    }
}
